package util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class ContentHandle {
	public static Document getContentFromUrl(String url, String para) {
		try {
			
			Document doc;
			URL dataURL = new URL(url + para);			
			HttpURLConnection cnn = (HttpURLConnection) dataURL.openConnection();
			cnn.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");			
			cnn.setReadTimeout(500000);
			cnn.setConnectTimeout(1000000);
			BufferedReader reader = new BufferedReader(new InputStreamReader(cnn.getInputStream(), Charset.forName("utf-8")));			
			String content = "";
			
			while(true)
			{
				String str = reader.readLine();
				if(str==null) break;
				content+=str;				
			}
			
			doc = Jsoup.parse(content);
			return doc;
			
		} catch (Exception e) {
			return null;
		}
	}
}
